package com.dbh.company.commuting;

import com.uber.h3core.H3Core;
import com.uber.h3core.util.LatLng;

import java.io.IOException;
import java.util.List;

/**
 * @author dongbanghui
 * @create 2023/7/31
 */
public class Test3 {

    public static void main(String[] args) throws IOException {
        H3Core h3 = H3Core.newInstance();
        // 东方电子科技大厦(用户输入的地址)
        double originLat = 40.053734;
        double originLng = 116.313348;

        // 北京市海淀区上地七街1号(汇众大厦)
        double destLat = 40.052907;
        double destLng = 116.314085;
        // H3分辨率
        int res = 8;
        long index = h3.latLngToCell(originLat, originLng, res);
        String s = h3.latLngToCellAddress(originLat, originLng, res);
        System.out.println("H3地址：" + index);

        long index2 = h3.latLngToCell(destLat, destLng, res);
        System.out.println("H3地址2：" + index2);

        // 在源索引的k距离内生成索引
        List<Long> list = h3.gridDisk(index, 21);
        System.out.println(list);
//
//        // 根据index反向解析出经纬度
        for (Long h3Index : list) {
            LatLng latLng = h3.cellToLatLng(h3Index);
            System.out.println(latLng);
        }

        // 按环拆分输出
//        List<List<Long>> lists = h3.gridDiskDistances(index, 21);
//        System.out.println(lists);

        // 计算两个索引之间的距离(环数)
        long l = h3.gridDistance(index, 613363303827111935L);
        System.out.println(l);

        //
        long numCells = h3.getNumCells(res);
        System.out.println(numCells);

    }
}
